package com.wceManage.manage.Emily;

import com.wceManage.beans.EUser;
import com.wceManage.beans.SysUser;
import com.wceManage.beans.page.PageList;
import com.wceManage.manage.util.UserUtils;
import com.wceManage.services.CourseService;
import com.wceManage.services.EmilyUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author jiangwei
 * @since 18/6/4
 */
@Controller
@RequestMapping("Emily/customer")
public class EmilyCustomerController {

    @Autowired(required = false)
    private CourseService courseService;

    @Autowired(required = false)
    private EmilyUserService emilyUserService;

    /**
     * 查询列表
     *
     * @param user
     * @return
     */
    @RequiresPermissions("sys:customer:view")
    @RequestMapping(value = {"", "/", "list"})
    public String list(EUser user, HttpServletRequest request)
            throws InstantiationException, IllegalAccessException {

        request.setAttribute("user", user);

        return "Emily/euserList";
    }

    /**
     * 异步获取list资源
     *
     * @param pageList
     * @param euser
     * @return
     */
    @RequiresPermissions("sys:customer:view")
    @RequestMapping("asynList")
    @ResponseBody
    public PageList asynList(PageList pageList, EUser euser) {
        SysUser user = UserUtils.getUser();

        if (user != null) {
            euser.setExp(courseService.findSystemId(user.getAccount()));
        }
        return emilyUserService.queryPage(pageList, euser);
    }
}
